package com.ctl.utils.jsondeserializer;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import lombok.extern.slf4j.Slf4j;
import org.bson.types.ObjectId;

import java.io.IOException;

/**
 * <p>Title: a</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2019</p>
 * <p>Company: www.ctl.com</p>
 *
 * @author ctl
 * @version 1.1
 * @date 2024-11-13 16:54
 */
@Slf4j
public  class ObjectIdDeserializer extends JsonDeserializer<ObjectId> {
    @Override
    public ObjectId deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
        try {
            String objectId = p.getValueAsString();
            return new ObjectId(objectId);
        } catch (IOException e) {
            log.error("ObjectIdDeserializer.deserialize.error",e);
            return null;
        }
    }
}